class Product {
  id: number;
  price: number;

  constructor(price: number) {
    this.id = Math.floor(Math.random() * 1000);
    this.price = price;
  }
  calculateTax(): number {
    return this.price < 30 ? 0 : this.price * 0.05;
  }

  getProductInfo(): string {
    return `Product: ${this.id}, Price: ${this.price}`;
  }
}

class Person {
  name: string;
  age: number;
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }

  print() {
    console.log(this.name);
  }
}

const p1 = new Person("jina", 18);

console.log(p1.name);
p1.print();

// forexpalme
class Book extends Product {
  title: string;
  pages: number;

  constructor(title: string, pages: number) {
    super(30);
    this.title = title;
    this.pages = pages;
  }

  // 如果你需要重写父类的方法，可以使用override关键字，函数名字要和父类的一样
  override getProductInfo(): string {
    return `Book: ${this.title}, Pages: ${this.pages}, Price: ${this.price}`;
  }
}

const book1 = new Book("The Great Gatsby", 200);
console.log(book1.calculateTax());
console.log(book1.getProductInfo());

// 假如你有TV电视
class TV extends Product {
  brand: string;
  size: number;

  constructor(brand: string, size: number) {
    super(100);
    this.brand = brand;
    this.size = size;
  }

  override getProductInfo(): string {
    return `TV: ${this.brand}, Size: ${this.size}, Price: ${this.price}`;
  }
}

// shopping cart
class Shop extends Product {
  constructor() {
    super(30);
  }
}
const shop1 = new Shop();
// 当你不重写父类的方法的时候，也是可以用的，只不过这个方法是父类的方法，并且是public的
console.log(shop1.getProductInfo());
